npm/yarn安装node |
您所在的位置:网站首页 › canvas gpu › npm/yarn安装node |
问题
在 nodejs 环境里想使用 canvas 这个包做一些可视化的工作,本地调试没问题,放到服务器上就发现怎么也安装不成功这个包了,经过一些尝试,最终成功解决。 解决无论遭遇什么问题,是 node-gyp 报错也好还是卡住也好,安装直接失败也好,你都可以直接通过本地编译这个包来解决。 本地编译可以看到 官方说明 你可以自己编译这个包: ![]() 通过 --build-from-source 这个选项。 安装依赖环境要编译这个包,第一步,先按照官方 readme 上 Compiling 一栏写的: ![]() 把编译环境的依赖装好,我是 Ubuntu,所以安装: sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev其他的系统请对照表格自行安装基础依赖。 编译安装假如你是 yarn 管理依赖,在项目根目录执行以下命令去安装依赖即可: npm_config_build_from_source=true yarn install运行了这个命令,就相当于 npm 的: npm install --build-from-source注:在 yarn 命令行中如果要 custom npm 的 config,需要以设定环境变量的方式,所以你需要 --build-from-source 这个 npm 的 config 时,就需要设定 npm_config_build_from_source=true ,他遵循 npm_config_{snake_case_param}=true/false 这个规则,详见官方说明( yarn/toc-npm-config ) 之后就可以编译安装成功了。 如果你是用的 npm 来管理项目依赖,使用 npm install --build-from-source 去编译时可能会报权限错误: gyp WARN EACCES current user (“ubuntu”) does not have permission to access the dev dir “/root/.cache/node-gyp/8.10.0” gyp WARN EACCES attempting to reinstall using temporary dev dir “/root/5000-node/node_modules/canvas/.node-gyp” gyp WARN install got an error, rolling back install gyp WARN install got an error, rolling back install 这个使用使用 --unsafe-perm 免掉权限即可: npm --build-from-source --unsafe-perm install中途可能会有很多 warning 警告,比如 node-gyp 升级的相关信息: npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future 这些不去管他也是没有问题的,我们只需要解决一个问题:如何编译安装 canvas 这个包即可。 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |